﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
namespace docinternational
{
    public partial class InternationalDoctorSearchResults : System.Web.UI.Page
    {
        //MOVE to connection string value when live please...
        //--OLD ONEstring localConnect = @"Data Source=SBS-0SIZCRA2UA9\SQLEXPRESS;User ID=pdonovan;Password=Pj854q@;Trusted_Connection=false;Initial Catalog=DOC";
        //string localConnect = @"Data Source=CELLAR;User ID=pdonovan;Password=DocDoc;Trusted_Connection=false;Initial Catalog=DOC_CALENDAR";
        string localConnect = @"server=184.172.129.250;database=dbhaelthcare-dev;uid=findadoc;pwd=findadoc!@#$%;pooling=false;MultipleActiveResultSets=True;Min Pool Size=20;Max Pool Size=500;Connection Timeout=500"; 
        string remoteConnect ="server=FINDADOCINC;database=dbhaelthcare-dev;uid=findadoc;pwd=findadoc!@#$%;pooling=false;MultipleActiveResultSets=True;Min Pool Size=20;Max Pool Size=500;Connection Timeout=500";
        public bool isLive = false;
        //////////CHange to true when publishing captain karate
        //i know, use our one connect.. IN a minute..
        string countryID = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            
            System.Text.StringBuilder displayValues =
            new System.Text.StringBuilder();
            System.Collections.Specialized.NameValueCollection
                postedValues = Request.Form;
            String nextKey;
            for (int i = 0; i < postedValues.AllKeys.Length; i++)
            {
             //   Response.Write("loop:" + i + "<br/>");
                nextKey = postedValues.AllKeys[i];
                if (nextKey.Substring(0, 2) != "__")
                {
                    displayValues.Append("<br>");
                    displayValues.Append(nextKey);
                    displayValues.Append(" = ");
                    displayValues.Append(postedValues[i]);
                    //KLUGE for now only..until I Have time..
                    if (nextKey.Equals("INT_LOCS"))
                    {
                        this.countryID = postedValues[i];
                        //Response.Write("setting var countryID to " + countryID);
                        break;
                    }
                }
            }
           
            if ( countryID !=null && countryID!="")
            {                
                //Response.Write("Country=" + this.countryID + "<br/>");
                getRecords();
            }
            else
            {

                Response.Write("<B>ERROR: NO USER NAME!! Catastrophic!</B>" );
                this.countryID = "-1";
            }
            
        }
        private void getRecords()
        {
            //connect first
            string fullCmd = " Select * from SBS_ACC_COUNTRYDETAILS where countryID=" + this.countryID + " ORDER BY isFeatured DESC ";
            string conn = "";
            if (this.isLive == true)
                conn = remoteConnect;
            else
                conn = localConnect;
            SqlDataAdapter ad = new SqlDataAdapter(fullCmd, conn);

            DataSet ds = new DataSet();
            ad.Fill(ds, "ACC_COUNTRYDETAILS ");
            DataTable dt = ds.Tables[0];
             result.InnerHtml += "<table width=\"100%\" >";
            //title
            // result.InnerHtml += "<td colspan=\"4\">" + country + "
             result.InnerHtml += "<style type=\"text/css\" media=\"screen\">";            
            // result.InnerHtml += ".sbsResults { ";
             result.InnerHtml += ".sbsResultsTitle {";
             result.InnerHtml += " background:#FFCC99;";
             result.InnerHtml += "}";
             result.InnerHtml += "font-family: Verdana, Arial, Helvetica, sans-serif;font-size: 9px;color: #6B6B6B;}";
             result.InnerHtml += "#mainBlock { background:#E9E9E9; }";
             result.InnerHtml += "#mainBlockAlt { background:#F5F5F5;}";            
             result.InnerHtml += "</style>";
            //featured
            if (this.countryID.Equals("120"))
            {
               
            }
          
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow drow = dt.Rows[i];
                bool bFeatured=false;
                string hosp = drow["Hospital"].ToString();
                string link = "";
                if (i == 0)
                {
                    //1, check for any featured possible
                    //2.setup headers just once.
                    string sFeat = drow["isFeatured"].ToString();
                    if (sFeat.Equals("1"))
                    {
                        bFeatured = true;
                        string imgName = drow["featuredImage"].ToString();
                         result.InnerHtml += "<tr>";
                         result.InnerHtml += "<td colspan=\"5\" style='background-color:#f4f4f4;padding:20px'>";
                         result.InnerHtml += "<table width=100% style='background-color:#fff;border:1px solid #E9E9E9;line-height:18px;font-size:10px;font-family:Verdana,Arial'>";
                         result.InnerHtml += "<tr>";
                         result.InnerHtml += "<td align='center'><h2 style='color:#FF6C00'>Featured Institution</h2><strong>" + hosp + "</strong><br/>";
                         result.InnerHtml += "<img style='float:left;margin: 10px 10px 0px 0px;'src=\"http://www.findadoc.com/images/featured/" + imgName + "\" alt='Medical Tourism and Hospital Rating System'>";
                         result.InnerHtml += "<p>&nbsp;</p>";
                        string featuredText = drow["featuredText"].ToString();
                         result.InnerHtml += featuredText;
                        // result.InnerHtml += "Dallah IVF Center is the largest destination in the region for the treatment of in-vitro fertilization and is considered to be the most technologically sophisticated. It has 22 women doctors who provide outstanding treatment for infertility and assisted conception. Established in 1987, the hospital has 220 beds and an out-patient department that is now visited by more than a thousand patients a day. Professor Mohammad R. Al-Fagih, the medical superintendent of Dallah Healthcare Co. says the burgeoning role of the private sector in healthcare in the kingdom has resulted from the government's inability to meet fully the needs of a rapidly growing population that is very demanding in its health needs.";
                        link = drow["featuredLink"].ToString();
                        if (!link.Equals(""))
                        {
                             result.InnerHtml += "<p>";
                             result.InnerHtml += "<a href=\"" + link + "\" target=_blank>" + "View Web Site</a>";                                                        
                             result.InnerHtml += "</p>";
                            
                            //twitt baby http://twitter.com/home/?status=
                           
                        }
                         result.InnerHtml += "</td>";
                         result.InnerHtml += "<tr>";
                         result.InnerHtml += "</table>";
                         result.InnerHtml += "</tr>";
                         result.InnerHtml += "</tr>";
                    }
                     result.InnerHtml += "<tr>";                                        
                    //tweet stuff here
                    if (link.Equals(""))//for non featured sites...
                        link = "http://www.findadoc.com/International.aspx";
                    string twit = "http://twitter.com/home/?status=International+FindaDoc+and+Medical+Tourism+Link+is+here>>+" + link;
                     result.InnerHtml += "<td width='35%'>";
                     result.InnerHtml += "<a href=\"" + twit + "\" target=\"_blank\" title='Findadoc.com provides propietary rating systems for US hospitals and International Hospitals as well.'>";
                     result.InnerHtml += "<img src=\"http://www.findadoc.com/images/featured/twitter.png\" border='0'>";
                     result.InnerHtml += "</a>";
                    //now the text
                     result.InnerHtml += "&nbsp;<font color=\"#AC6648\">Tweet This!</font>";
                     result.InnerHtml += "</td>";//end tweet
                     result.InnerHtml += "<td colspan=4 align='left'><a href='SBS_SearchForm.aspx'>Search Again</a></td>";
                     result.InnerHtml += "<tr>";
                     result.InnerHtml += "<tr height=\"15\"><td width=\"35%\" class='sbsResultsTitle'>Hospital/Institution</td>";
                     result.InnerHtml += "<td width=\"25%\" class='sbsResultsTitle'>Location</td>";
                     result.InnerHtml += "<td width=\"15%\" class='sbsResultsTitle'>Program</td>";
                     result.InnerHtml += "<td width=\"15%\" class='sbsResultsTitle'>First Accredited</td>";
                     result.InnerHtml += "<td width=\"10%\" class='sbsResultsTitle'>Rating</td>";
                    
                    
                }
                 result.InnerHtml += "<tr>";
                string css = "mainBlock";
                if (i % 2 == 0)
                    css = "mainBlockAlt";

                
                string title = drow["Title"].ToString();
                string prog = drow["Program"].ToString();
                string sRating = drow["rating"].ToString();
                string firstacc = drow["FirstAccredited"].ToString();
                string sID = "";
                /*if (isLive == false)
                {
                    sID = ":" + drow["ID"].ToString();

                }*/
                string img = "";
                if ( i==0 && bFeatured == true)
                    img ="<img src=\"http://www.findadoc.com/images/featured/bookmarkgrey.png\" width='24' height='24' alt='Featured International Hospital at findadoc.com '>" ;
                 result.InnerHtml += "<td id=\"" + css + "\">" + hosp + "&nbsp;" + img +  "</td>";
                 result.InnerHtml += "<td id=\"" + css + "\">" + title + "</td>";
                 result.InnerHtml += "<td id=\"" + css + "\">" + prog + "</td>";
                 result.InnerHtml += "<td id=\"" + css + "\">" + firstacc + "</td>";
                Random r = new Random(8675309);                
                int rating = r.Next(72, 99);                                
                 result.InnerHtml += "<td id=\"" + css + "\">" + sRating + "</td>";
                 result.InnerHtml += "</tr>";
            }
             result.InnerHtml += "</table >";

        }
    }
}
